﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes {
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import flash.external.*;

    public class SurveyManager {

        private static var m_instance:SurveyManager = null;

        private var m_overlaySurveyUrl:String = null;
        private var m_isInitialized:Boolean = false;
        private var m_delay:int = 0;
        private var m_timer:Timer;
        private var m_interval:int;
        private var m_intervalChecker:Timer;
        private var m_lastActiveTime:uint;
        private var m_lastMousePos:Point;

        public static function get instance():SurveyManager{
            if (!m_instance){
                m_instance = new (SurveyManager)();
            };
            return (m_instance);
        }

        private function checkIfMouseMoved():Boolean{
            var _local1:Point = new Point(Global.stage.mouseX, Global.stage.mouseY);
            var _local2:Boolean;
            if (((this.m_lastMousePos) && (_local1.equals(this.m_lastMousePos)))){
                _local2 = false;
            };
            this.m_lastMousePos = _local1;
            return (_local2);
        }
        public function initializeSurveyOverlay(_arg1:String):void{
            if (((!(this.m_isInitialized)) && ((_arg1.length > 0)))){
                this.m_overlaySurveyUrl = _arg1;
                this.m_delay = Global.gameSettings.getInt("surveyOverlayDelay", 30000);
                this.m_lastActiveTime = GlobalEngine.getTimer();
                this.m_intervalChecker = new Timer(1000);
                this.m_intervalChecker.addEventListener(TimerEvent.TIMER, this.intervalCheckerTimerHandler);
                this.m_intervalChecker.start();
                this.m_isInitialized = true;
            };
        }
        public function displaySurveyOverlay(_arg1:Boolean=false):void{
            if (((_arg1) || (((this.m_overlaySurveyUrl) && (ExternalInterface.available))))){
                ExternalInterface.call("theFarmOverlay.showSurveyOverlay", this.m_overlaySurveyUrl);
            };
        }
        private function intervalCheckerTimerHandler(_arg1:TimerEvent):void{
            if (this.checkIfMouseMoved()){
                this.m_lastActiveTime = GlobalEngine.getTimer();
            } else {
                if ((this.m_lastActiveTime + this.m_delay) < GlobalEngine.getTimer()){
                    this.displaySurveyOverlay();
                    this.m_intervalChecker.stop();
                };
            };
        }

    }
}//package Classes 
